
import java.io.UnsupportedEncodingException;
import java.util.Random;

public class Generator 
{
    private  Random random = new Random();
    private int constant_start_number = 32;
    private int constant_end_number = 64;
    private int randLetters(int start_number, int end_number)
    {
        int modul = end_number - start_number + 1;
        int rand_number = random.nextInt() % modul;
        if (rand_number < 0)
                rand_number = -rand_number;
        System.out.println("\n Rand_number: " + rand_number);
        return rand_number + start_number;
    }
    public String getRandomString(int size, String language) 
    {
        int start_number = getStartNumber(language);
        int end_number = getEndNumber(language);
        try
        {
            byte b[] = new byte[size];
            for (int i = 0; i < (size - 1); i += 2)
            {
                int rand_alphabet_letter = randLetters(start_number, end_number);
                int rand_constant_letters = randLetters(constant_start_number, constant_end_number);
                if(isCorrectNumber(rand_alphabet_letter))
                    b[i] = (byte)rand_alphabet_letter;
                b[i+1] = (byte)rand_constant_letters;
            }
            String utf = new String(b, "KOI8_R");   
            System.out.print("\n Random String: " + utf);
            return utf;
        }
        catch(UnsupportedEncodingException ex) 
        {
            System.out.print("\n Can not convert to KOI8_R " + ex);
            return new String();
        }          
    }
    public String getSequenceString(int size, String language, int count_letters) 
    {
        int start_number = getStartNumber(language);
        int end_number = start_number + count_letters;
        try
        {
            byte b[] = new byte[size];
            for (int i = 0; i < size; i += 1)
            {
                int rand_alphabet_letter = randLetters(start_number, end_number);
                b[i] = (byte)rand_alphabet_letter;
            }
            String utf = new String(b, "KOI8_R");   
            System.out.print("\n Sequence String: " + utf);
            return utf;
        }
        catch(UnsupportedEncodingException ex) 
        {
            System.out.print("\n Can not convert to KOI8_R " + ex);
            return new String();
        }          
    }
    private int getStartNumber(String language)
    {
        int start_number = 0;
        if(language.equals("English"))
            start_number = 65;//code A
        if(language.equals("Russian"))
            start_number = 192;//code ю, 193 - code a, 194 - code б; 195 - code ц
        return start_number;
    }
    private int getEndNumber(String language)
    {
        int end_number = 0;
        if(language.equals("English"))
            end_number = 122;
        if(language.equals("Russian"))
            end_number = 255;
        return end_number;
    }
    private boolean isCorrectNumber(int number)
    {
        boolean result = true;
        if((number == 91) && 
           (number == 92) && 
           (number == 93) && 
           (number == 94) && 
           (number == 95) && 
           (number == 96))
        {
            result = false;
        }
        return result;
    }
}
